package org.jeecg.modules.oms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.oms.service.ICfWindowDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 长风窗型确认文件-型材尺寸表 控制器
 */
@Slf4j
@Api(tags = "长风窗型确认文件-型材尺寸表")
@RestController
@RequestMapping("/oms/cfProfileSizeTable")
public class CfProfileSizeTableController {

    @Autowired
    private ICfWindowDataService cfWindowDataService;
    
    /**
     * 根据明细ID获取型材尺寸信息
     */
    @AutoLog(value = "长风窗型确认文件-型材尺寸表-根据明细ID获取型材尺寸信息")
    @ApiOperation(value = "长风窗型确认文件-型材尺寸表-根据明细ID获取型材尺寸信息", notes = "长风窗型确认文件-型材尺寸表-根据明细ID获取型材尺寸信息")
    @GetMapping(value = "/listByDetailId")
    public Result<?> listByDetailId(@RequestParam(name = "detailId") String detailId) {
        try {
            List<Map<String, Object>> profileSizeList = cfWindowDataService.getProfileSizeByDetailId(detailId);
            return Result.OK(profileSizeList);
        } catch (Exception e) {
            log.error("获取型材尺寸信息失败", e);
            return Result.error("获取型材尺寸信息失败: " + e.getMessage());
        }
    }
    
    /**
     * 根据明细ID、软件类型和窗号获取型材尺寸信息
     */
    @AutoLog(value = "型材尺寸表-根据明细ID、软件类型和窗号获取型材尺寸信息")
    @ApiOperation(value = "型材尺寸表-根据明细ID、软件类型和窗号获取型材尺寸信息", notes = "型材尺寸表-根据明细ID、软件类型和窗号获取型材尺寸信息")
    @GetMapping(value = "/listByDetailIdAndType")
    public Result<?> listByDetailIdAndType(
            @RequestParam(name = "detailId") String detailId,
            @RequestParam(name = "softwareType", defaultValue = "0") String softwareType,
            @RequestParam(name = "windowNo", required = false) String windowNo) {
        try {
            List<Map<String, Object>> profileSizeList;
            
            // 根据软件类型和是否有窗号选择不同的服务方法
            if ("0".equals(softwareType) || "0" == softwareType) {
                if (windowNo != null && !windowNo.isEmpty()) {
                    profileSizeList = cfWindowDataService.getProfileSizeByDetailIdAndWindowNo(detailId, windowNo);
                } else {
                    profileSizeList = cfWindowDataService.getProfileSizeByDetailId(detailId);
                }
            } else {
                // 新格尔软件类型(1)，调用对应的服务方法
                if (windowNo != null && !windowNo.isEmpty()) {
                    profileSizeList = cfWindowDataService.getXgeProfileSizeByDetailIdAndWindowNo(detailId, windowNo);
                } else {
                    profileSizeList = cfWindowDataService.getXgeProfileSizeByDetailId(detailId);
                }
            }
            
            return Result.OK(profileSizeList);
        } catch (Exception e) {
            log.error("获取型材尺寸信息失败", e);
            return Result.error("获取型材尺寸信息失败: " + e.getMessage());
        }
    }
} 